<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        .tab {
            margin-top: 40px;
        }

        ul {
            width: 80%;
            height: 50px;
            list-style: none;
            line-height: 50px;
            margin: auto;
            display: flex;
            justify-content: space-between;
            border-bottom: 1px solid rgb(169, 169, 169);
        }

        li {
            text-align: center;
            width: 20%;
        }
        .tab_body {
            width: 80%;
            margin: 20px auto;
        }

        .tab_list {
            height: 200px;
            margin: 20px auto;
            display: flex;
            border-bottom: 1px solid black;
        }

        img {
            width: 230px;
        }
        h4{
            width: 700px;
            height: 40px;
            line-height: 40px;
            margin-top: 2px;
        }
    </style>
</head>

<body>
    <div class="tab">
        <div class="tab_head">
            <ul>
                <li>精选</li>
                <li>游戏</li>
                <li>手机</li>
                <li>数码</li>
                <li>产品</li>
            </ul>
        </div>
        <div class="tab_body">
            <div>
                <div class="tab_list">
                    <img src="./bjt2.png">
                    <div>
                        <h4>这是精选页面</h4>
                    </div>
                </div>
            </div>
            <div>
                <div class="tab_list">
                    <img src="./play.jpg">
                    <div>
                        <h4>这是游戏页面</h4>
                    </div>
                </div>
            </div>
            <div>
                <div class="tab_list">
                    <img src="./bjt3.jpg">
                    <div>
                        <h4>这是手机页面</h4>
                    </div>
                </div>
            </div>
            <div>
                <div class="tab_list">
                    <img src="./timer.jpg">
                    <div>
                        <h4>这是数码页面</h4>
                    </div>
                </div>
            </div>
            <div>
                <div class="tab_list">
                    <img src="./car.jpg">
                    <div>
                        <h4>这是产品页面</h4>
                    </div>
                </div>
            </div>
        </div>
        <script>
            let li = document.querySelector('ul').querySelectorAll('li');
            let list = document.querySelector('.tab_body').querySelectorAll('.tab_list');
            console.log(list);
            for (let i = 0; i < li.length; i++) {
                list[0].style.display = 'flex';
                list[i].style.display = 'none';
                li[0].style.color = 'red'
                li[0].style.borderBottom = '5px solid red'
                li[i].onclick = function () {
                    for(let i = 0; i < li.length; i++) {
                        console.log(list.length);
                        li[i].style.color = 'black';
                        li[i].style.borderBottom = 'none'
                        list[i].style.display = 'none';
                        console.log(list[i]);
                    }
                    list[i].style.display = 'flex';
                    this.style.color = 'red';
                    this.style.borderBottom = '5px solid red'
                }
            }
        </script>
    </div>
</body>

</html>